<!-- 共享空间，查看更多 -->
<template>
	<view class="classroomListContainer">
		<scroll-view :scroll-y="isScroll" :style="{ height: windowHeight + 'px' }" @scrolltolower="lower" :scroll-top="scrollTop">
			<block v-if="dataList.length > 0">
				<view class="yuyueItem" v-for="item,index in dataList" :key="index" @click="jumpPage(item)">
					<view class="yuyueTxt txtOverFlow">{{item.laboratoryName}}</view>
					<view class="yuyueSubTxt txtOverFlow">{{item.minPersonCount}}-{{item.maxPersonCount}}人<br/>
						{{item.laboratoryExplain}}</view>
						<view class="yuyueSubTxt txtOverFlow2 red"  :style="{'line-height': '26rpx'}">
							{{item.isApply==0 && !ignoreApplayStatus?'待申请':item.relState==0?'待审核':item.relState==1?'可预约':'审核不通过'}}
						</view> 
				</view>
				
			</block>
			<view v-else class="noDataTxt">暂无数据</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				classroomType: 1,//0共享空间，1一级分类，2级分类，3级分类
				typeOneId: '',	//一级分类id
				dataList:[],
				page: 1,
				limit: 20,
				isScroll: true,
				windowHeight: 0,
				scrollTop: 0,
        ignoreApplayStatus: false,
				hasMoreData: false,//是否还有更多数据
			}
		},
		onLoad(options) {
			let _this = this;
			wx.getSystemInfo({
				success: function(res) {
					_this.windowHeight = res.windowHeight;
				}
			})
			this.classroomType = options.flag;
			this.typeOneId = options.typeOneId;
      this.ignoreApplayStatus = options.ignoreApplayStatus === '1';
		},
		onShow() {
			this.searchClassroomList();
		},
		methods: {
			searchClassroomList() {
				let _this = this;
				let params = {
					channelId: getApp().globalData.channelId,
					page: _this.page,
					limit: _this.limit,
					token: getApp().globalData.token,
					roomState: 1,//教室是否启用：0：否1：是
				}
				if(this.classroomType == 0) {
					params.isShare = 1;
				}else {
					params.typeOne = this.typeOneId;
				}
				this.$utils.requestFun('/stadium/stadium/api/getH5ClassroomListApi',params,'GET').then(res=> {
					console.log(res)
					// this.dataList = res.data.data.data ? res.data.data.data : [];
					let dataListData = _this.dataList;
					if(res.data.data.data && res.data.data.data.length > 0) {
						if(_this.page == 1) {
							dataListData = [];
						}
						let dataList = res.data.data.data;
						if(dataList.length < _this.limit) {
							_this.dataList = dataListData.concat(dataList);
							_this.hasMoreData = false;
						}else {
							_this.dataList = dataListData.concat(dataList);
							_this.hasMoreData = true;
							_this.page = _this.page++;
						}
					}else {
						if(_this.page == 1) {
							_this.dataList = [];
						}else {
							_this.dataList = dataListData;
						}
					}
				})
			},
			// 触底加载更多
			lower(e) {
				if (this.hasMoreData) {
					let page = this.page+1;
					this.page = page;
					this.searchClassroomList();
				} else {
					uni.showToast({
						title: '没有更多数据',
						icon: 'none'
					})
				}
			},
			jumpPage(temp) {
				let id = temp.laboratoryId??''
				let merchantId = temp.merchantId??''
				if(0 == temp.isApply && !this.ignoreApplayStatus){
					uni.showToast({
						title: '您还未申请教室！',
						icon: 'none'
					})
					return
				}
				if(0 == temp.relState){
					uni.showToast({
						title: '您申请的教室未审核！',
						icon: 'none'
					})
					return
				}
				if(2 == temp.relState){
					uni.showToast({
						title: '您申请的教室审核不通过！',
						icon: 'none'
					})
					return
				}
				this.$utils.requestFun('/base/merchant/api/getClientMerchantNoticeApi', {
					merchantId: merchantId
				}, 'GET').then(res => {
					console.log("inde_res===",res)
					let _isHas = res?.data?.data?.isHas||0;
					if(_isHas == 0){
						uni.navigateTo({
							url: '/pages/classroom/classroom?laboratoryId='+id,
						});
					}else{
						let _notice = res?.data?.data?.notice||{};
						
						uni.showModal({
							title: _notice.noticeTitle,
							showCancel:false,
							content: _notice.noticeContent,
							success: function(res) {
								uni.navigateTo({
									url: '/pages/classroom/classroom?laboratoryId='+id,
								});
							}
						});
					}
							
				})
			},
			//下拉刷新
			refreshPull() {
				this.page = 1;
				this.dataList = [];
				this.hasMoreData = false;
				this.scrollTop = 0;
				this.searchClassroomList();
			}
		}
	}
</script>

<style>
	.classroomListContainer {
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		padding-top: 30rpx;
	}
	.txtOverFlow {
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
	}
	.flex {
		display: flex;
	}
	.noDataTxt {
		color: #999999;
		text-align: center;
		margin: 100rpx 0;
		line-height: 200rpx;
	}
	.yuyueItem {
		width: 45%;
		height: 230rpx;
		background: #F6F6F6;
		border: 1px solid #EEEEEE;
		border-radius: 20rpx;
		float: left;
		margin-left: 22rpx;
		margin-bottom:20rpx;
		text-align: center;
	}
	
	.yuyueTxt {
		font-size: 26rpx;
		font-weight: bold;
		color: #222222;
		line-height: 54rpx;
		margin-top: 15rpx;
	}
	.yuyueSubTxt {
		font-size: 24rpx;
		color: #666666;
		line-height: 54rpx;
	}
	.red {
		color: red !important;
	}
</style>
